package com.dc.designPattern._15_iterator.impl;

import java.util.Iterator;

/**
 * Description: 迭代器模式_客户端
 *
 * 需求：将书（Book）放到书架（BookShelf）中，并将书名按顺序显示。
 *
 * @author: gdc
 * @date: 2021/5/19
 * @version 1.0
 */
public class Client {

    public static void main(String[] args){
        // step 1 创建书架类，并并添加图书
        BookShelf bookShelf = new BookShelf();
        bookShelf.addBook(new Book("西游记"));
        bookShelf.addBook(new Book("三体"));
        bookShelf.addBook(new Book("坏蛋是怎样炼成的"));
        bookShelf.addBook(new Book("星辰变"));

        // step 2 获取具体迭代器
        Iterator iterator = bookShelf.iterator();

        // step 3 当包含数据时，进行获取
        while (iterator.hasNext()) {
            Book book = (Book) iterator.next();
            System.out.println(book.getName());
        }
    }
}
